// pages/bankcard/bankcard.js
import { Agent } from "../agent/agent-model.js"
var agent = new Agent();

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		loadingHidden: false
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		this._loadData();
	},
	_loadData:function(){
		agent.getAgentBankCard((data) => {
			this.setData({
				bankCards: data,
				loadingHidden: true
			})
		})
	},
	addBankCard: function () {
		wx.navigateTo({
			url: '../addbankcard/addbankcard',
		})
	},
	deleteBankCard:function(e){
		console.log(e)
		var bankCardId = e.currentTarget.dataset.id;
		var index = e.currentTarget.dataset.index;
		var that = this;
		wx.showModal({
			title: '提示',
			content: '是否删除尾号为' + that.data.bankCards[index].bank_end+'的提现银行卡',
			success:function(res){
				if (res.confirm) {
					agent.deleteBankCard(bankCardId,(data)=>{
						if(data.msg){
							that._loadData();
							agent.showToast('删除成功');
						}
					})
				} else if (res.cancel) {
					agent.showToast('取消');
				}
			}
		})
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})